
$(document).ready(function () {
    var id = getPar1("id");
    if (id != "" && id != undefined) { //编辑时
        setTimeout(function () {
            var fieldname = $("input[name=FieldName]");
            fieldname.attr("readonly", "readonly");
            fieldname.css("background", "whitesmoke");
        }, 200);
    }
    $("#TableName").change(function () {
        var tabelName = $("#TableName").val(); //表名
        if (tabelName != undefined && tabelName != "") {
            //根据表名获取字段
            var url = "../EHR/hrSalaryAjax.aspx?flag=getfieldbytable&table=" + tabelName;
            $.ajax({
                type: 'get',
                url: url,
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        AddOneRecordToDetail(data[i].name);
                    }
                    if (data.length == 0) {
                        for (var i = 0; i < _DataTable.Rows.length; i++) {
                            var rows = _DataTable.getRow(i);
                            _DataTable.Rows.REMOVE(rows);
                        }
                        $("#Details tbody tr").remove();
                    }
                },
                error: function (data) {
                }
            });
        }
        else {
            for (var i = 0; i < _DataTable.Rows.length; i++) {
                var rows = _DataTable.getRow(i);
                _DataTable.Rows.REMOVE(rows);
            }
            $("#Details tbody tr").remove();
        }
    });
});

//增加一条数据
function AddOneRecordToDetail(value) {
    _DataTable.AddRow();
    var fieldname = $("input[name=FieldName]:last");
    var fielddes = $("input[name=FieldDes]:last");
    fieldname.attr("readonly", "readonly");
    fieldname.css("background", "whitesmoke");
    fieldname.val(value);
    fielddes.val(value);
}

var fnCustomAdd = function () {
    const_EditEntity = "salSalaryRelationTable";
    var pagetitle = "新增薪资关联表";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity));
    parent.NeedRefreshPage = this;
}

var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "salSalaryRelationTable";
    var pagetitle = "修改薪资关联表—" + record.getData("Name");
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}
